﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Modulo1
{
    class Program
    {
        static void Main(string[] args)
        {
            if( args.Count() != 4 )
            {
                Console.WriteLine("Args error!");
                return;
            }
            var dataEntreFileName = args[0];
            var dataOutputFileName = args[1];
            var logFileName = args[2];
            var errFileName = args[3];

            int entryRegisterCout = 0;
            int procesedResgisterCount = 0;
            int outputRegisterCount = 0;

            var outputFile = new StreamWriter(dataOutputFileName);
            var logFile = new StreamWriter(logFileName);
            var errFile = new StreamWriter(errFileName);

            logFile.WriteLine("==== Module #1====");
            logFile.WriteLine(DateTime.Now.ToString());
            errFile.WriteLine("==== Module #1====");
            errFile.WriteLine(DateTime.Now.ToString());

            var chars = File.ReadAllBytes(dataEntreFileName);
            var sb = new StringBuilder();
            foreach(char c in chars)
            {
                entryRegisterCout++;
                if( Char.IsLetter(c) )
                {
                    sb.Append(Char.ToLower(c));
                }
                else
                {
                    var outputString = sb.ToString();
                    if( outputString.Length > 0 )
                    {
                        outputFile.WriteLine(outputString);
                        sb.Clear();
                        outputRegisterCount++;
                    }
                }
                procesedResgisterCount++;
            }

            logFile.WriteLine("Input Register Count : " + entryRegisterCout);
            logFile.WriteLine("Procesed Register Count : " + procesedResgisterCount);
            logFile.WriteLine("Output Register Count : " + outputRegisterCount);
            logFile.WriteLine(DateTime.Now.ToString());
            errFile.WriteLine(DateTime.Now.ToString());

            outputFile.Flush();
            logFile.Flush();
            errFile.Flush();

            outputFile.Close();
            logFile.Close();
            errFile.Close();
        }
    }
}
